package com.example.mapper;

import com.example.entity.Employee;
import com.example.query.EmpQueryParam;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;


import java.time.LocalDate;
import java.util.List;
import java.util.Map;

@Mapper
public interface EmployeeMapper {

    /**
     * 查询总数
     * @return 总记录数
     */
    @Select("select count(*) from t_emp e left join t_dept d on e.dept_id = d.id")
    Long count();

    /**
     * 分页查询员工信息
     *
     * @return 分页结果
     */
//    @Select("select e.*, d.name deptName from t_emp e left join t_dept d on e.dept_id = d.id" +
//            " where e.name like concat('%', #{name}, '%')" +
//            " and e.gender = #{gender}" +
//            " and e.entry_date between #{begin} and #{end}")
//    List<Employee> list(String name, Integer gender, LocalDate begin, LocalDate end);
    List<Employee> list(EmpQueryParam empQueryParam);

    @Select("select e.*, d.name deptName from t_emp e left join t_dept d on e.dept_id = d.id")
    List<Employee> findAll();

    @Options(useGeneratedKeys = true, keyProperty = "id")
    @Insert("INSERT INTO `t_emp` (`username`, `password`, `name`, `gender`, `phone`, `job`, `salary`, `image`, `entry_date`, `dept_id`, `create_time`, `update_time`, `create_by`, `update_by`) " +
            "VALUES (#{userName}, #{password}, #{name}, #{gender}, #{phone}, #{job}, #{salary}, #{image}, #{entryDate}, #{deptId}, #{createTime}, #{updateTime}, #{createBy}, #{updateBy})")
    void insert(Employee employee);

    void deleteByIds(List<Integer> ids);

    Employee selectById(Integer id);

    void updateById(Employee employee);

    List<Map<String, Object>> countEmpJobData();

    List<Map> countEmpGenderData();

    @Select("select * from t_emp where username = #{userName} and password = #{password}")
    Employee selectUsernameAndPassword(Employee employee);
}